'use strict';
let db = uniCloud.database();
let dbCmd = db.command;
exports.main = async (event, context) => {
 let {relevanceUserID} = event;
 let data = [];
 let projectResult = await db.collection("projects").where({ //自己创建的项目
	relevanceUserID,
	vaildDate:dbCmd.gt(new Date().getTime())
 }).get()
 
 let joinProjectResult = await db.collection("projects").where({ //获取加入的
	project:{
		applyPerson:dbCmd.elemMatch({
			opinion:1,
			userID:relevanceUserID
		})
	},
	vaildDate:dbCmd.gt(new Date().getTime())
 }).get()
 
 if(joinProjectResult.affectedDocs !== 0 || joinProjectResult.data.length !== 0){
	 data.push(...joinProjectResult.data)
 }
 if(projectResult.affectedDocs !== 0 || projectResult.data.length !== 0){
 	 data.push(...projectResult.data)
 }
 
 if(data.length > 0){
	 return{
		 status:0,
		 data
	 }
 } else {
	return{
		status:1,
		data:"没有数据"
	} 
 }
 
  return {
	  status:-1,
	  msg:"稍后重试"
  }
};
